/*
 * Copyright 2011 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package fr.gaellalire.jzip.test.macosx;

import org.rococoa.ID;
import org.rococoa.Rococoa;
import org.rococoa.cocoa.foundation.NSArray;
import org.rococoa.cocoa.foundation.NSObject;
import org.rococoa.cocoa.foundation.NSURL;


public class DragProvider {

    public DragProvider() {
    }

    private NSObject proxy;

    private ID id;

    public NSArray namesOfPromisedFilesDroppedAtDestination(final NSURL url) {
        NSMutableArray promisedDragNames = NSMutableArray.array();
//        if (null != url) {
//            final Local destination = LocalFactory.createLocal(url.path());
//            final PathPasteboard pasteboard = PathPasteboard.getPasteboard(controller.getSession());
//            for (Path p : pasteboard) {
//                p.setLocal(LocalFactory.createLocal(destination, p.getName()));
//                // Add to returned path names
//                promisedDragNames.addObject(NSString.stringWithString(p.getLocal().getName()));
//            }
//            if (pasteboard.size() == 1) {
//                if (pasteboard.get(0).attributes().isFile()) {
//                    pasteboard.get(0).getLocal().touch();
//                }
//                if (pasteboard.get(0).attributes().isDirectory()) {
//                    pasteboard.get(0).getLocal().mkdir();
//                }
//            }
//            final boolean dock = destination.equals(LocalFactory.createLocal("~/Library/Caches/TemporaryItems"));
//            DownloadTransfer transfer = new DownloadTransfer(pasteboard.copy(controller.getTransferSession())) {
//                @Override
//                protected void fireDidTransferPath(Path path) {
//                    if (dock) {
//                        WatchEditor editor = new WatchEditor(controller, path);
//                        editor.watch();
//                    }
//                    super.fireDidTransferPath(path);
//                }
//            };
//            if (dock) {
//                // Drag to application icon in dock.
//                controller.transfer(transfer, new TransferPrompt() {
//                    public TransferAction prompt() {
//                        return TransferAction.ACTION_OVERWRITE;
//                    }
//                });
//            } else {
//                controller.transfer(transfer);
//            }
//            pasteboard.clear();
//        }
        // Filenames
        return promisedDragNames;
    }

    protected NSObject proxy(Class<? extends NSObject> type) {
        if (null == proxy) {
            proxy = Rococoa.proxy(this, type);
        }
        return proxy;
    }

    protected org.rococoa.ID id(Class<? extends NSObject> type) {
        if (null == id) {
            id = this.proxy(type).id();
        }
        return id;
    }

    public org.rococoa.ID id() {
        return this.id(NSObject.class);
    }

}
